﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Patterns.EfCodeGeneration.Sample.Tests
{
    [TestClass]
    public class PatternTest
    {
        [TestMethod]
        public void SanityTest()
        {
            using (var uow = new UnitOfWorkPattern.MultiContextUnitOfWork())
            {
                using (var context = new Access.SampleEntities(uow))
                {
                    context.Accounts.Count();
                }
            }
        }

        [TestMethod]
        public void GenericsTest()
        {
            using (var uow = new UnitOfWorkPattern.MultiContextUnitOfWork())
            {
                Type contextType;
                Type entityBaseType;

                Assert.IsTrue(
                    UnitOfWorkPattern.TypeLookUp.IsTypeCompatible(
                        typeof(Model.Account), out contextType, out entityBaseType));

                var context = uow.GetContext(contextType) as UnitOfWorkPattern.EF.EfContext;

                var set = context.Set(entityBaseType);

                set.AsQueryable().Cast<Model.Account>().Count();
            }
        }
    }
}
